package HomeWork;



public class Student {
    private String name;
    private char sex;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) throws SexException{
        if(sex!='男'&&sex!='女'){
            throw new SexException("性别不正确");
        }
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException{
        if(age<15||age>50){
            throw new AgeException("年龄不正确");
        }
        this.age = age;
    }
}

class AgeException extends RuntimeException{
    public AgeException() {
    }

    public AgeException(String message) {
        super(message);
    }
}
class SexException extends  RuntimeException{
    public SexException() {
    }

    public SexException(String message) {
        super(message);
    }
}

class test{
    public static void main(String[] args) {

        Student student=new Student();
        try{
            student.setAge(90);
            student.setSex('2');
        }catch (AgeException e){
            System.out.println("年龄不正常");
           e.printStackTrace();
            System.out.println("案件");
        }catch (SexException e){
            System.out.println("性别不正常");
            e.printStackTrace();
        }


    }
}